package com.goodving.guli.bt.ui;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.goodving.guli.activity.RecordWeightActivity;
import com.goodving.guli.activity.WeightGoalSetActivity;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.model.C1981P;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.view.PageIndicator;

import cn.com.smartdevices.bracelet.chart.util.ChartData;
import cn.com.smartdevices.bracelet.chart.util.DynamicData;

/**
 * Created by john on 2015/12/2.
 */
public class PagerFragment extends Fragment {
    public DynamicView dynamicView; // f9478a
    private DynamicData mDynamicData; //f9479b
    public int type;
    private PageIndicator mPageIndicator;

    private void m14268a(DynamicView dynamicView, DynamicData c0802r) {
        if (this.type == 1) {
            dynamicView.m15116a(Keeper.readPersonInfoBaseConfig().getDaySportGoalSteps());
            dynamicView.m15126b(c0802r.m8787c());
            dynamicView.m15123a(ChartData.m8736a(getActivity(), c0802r.m8791d()));
            if (c0802r.m8795e() != 0) {
                dynamicView.m15131c(0);
                dynamicView.m15129b(ChartData.m8736a(getActivity(), c0802r.m8795e()));
            } else {
                dynamicView.m15131c(4);
            }
            dynamicView.m15134d(c0802r.m8797f());
            dynamicView.m15121a(c0802r.m8799g());
        } else if (this.type == 16) {
            dynamicView.m15136e(c0802r.m8801h());
            dynamicView.m15137f(c0802r.m8803i());
            dynamicView.m15127b(c0802r.m8808l());
        } else if (this.type == PersonInfo.INCOMING_CALL_DISABLE_BIT) {
            dynamicView.m15119a(c0802r.m8781b());
            dynamicView.m15114a(c0802r.m8810n(), c0802r.m8811o(), c0802r.m8812p(), c0802r.m8814r());
            dynamicView.m15132c(c0802r.m8813q());
            dynamicView.m15115a(c0802r.m8814r(), c0802r.m8818v(), c0802r.m8819w());
            dynamicView.m15135d(c0802r.m8815s());
        }
        GuliLog.tracePrintInfo("DynamicFragment", "BindData : " + c0802r + " , Mode : " + this.type);
    }

    public void onShortCutAction() { // m14270a
        Context activity = getActivity();
        Intent intent;
        if (this.type == PersonInfo.INCOMING_CALL_DISABLE_BIT) {
            intent = new Intent(activity, RecordWeightActivity.class);
            C1981P b = this.mDynamicData.m8781b();
            if (b != null) {
                intent.putExtra(WeightGoalSetActivity.f11178a, b.f11135c);
            } else {
                intent.putExtra(WeightGoalSetActivity.f11178a, -1);
            }
            startActivity(intent);
            C0668a.m8128a(activity, C0668a.gr, C0668a.gt);
        } else if (this.type == 1) {
            intent = new Intent("com.goodving.hm.health.action.RUNNING");
            intent.setPackage(getActivity().getPackageName());
            startActivity(intent);
            C0668a.m8128a(activity, C0668a.gr, C0668a.gs);
        }
    }

    public void m14271a(float f) {
        if (this.dynamicView != null) {
            this.dynamicView.m15113a(f);
        }
    }

    public void m14272a(PageIndicator c1858c) {
        this.mPageIndicator = c1858c;
        if (this.dynamicView != null) {
            this.dynamicView.m15118a(this.mPageIndicator);
        }
    }

    public void m14273a(Boolean bool) {
        if (this.dynamicView != null) {
            this.dynamicView.m15120a(bool);
        }
    }

    public void m14274a(boolean z) {
        if (this.dynamicView != null) {
            m14268a(this.dynamicView, this.mDynamicData);
            if (this.type == PersonInfo.INCOMING_CALL_DISABLE_BIT) {
                this.dynamicView.m15133c(true);
            } else {
                this.dynamicView.m15133c(z);
            }
        }
    }

    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        this.dynamicView.m15133c(true);
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            this.type = arguments.getInt(ChartData.KEY_MODE);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View dynamicView = new DynamicView(getActivity());
        this.dynamicView = (DynamicView) dynamicView;
        // start  to show the dynamic view
        this.dynamicView.m15138g(this.type);
        this.mDynamicData = ChartData.m8731a();
        // show the data
        m14268a(this.dynamicView, this.mDynamicData);
        // update the text data for the detailed information
        this.dynamicView.m15112a();
        this.dynamicView.m15118a(this.mPageIndicator);
        return dynamicView;
    }
}